package com.central.apps.controller;

import com.central.apps.entity.EsFile;
import com.central.apps.service.EsFileService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * es控制器
 *
 * @author JHY
 * @date 2022/11/10
 */
@Slf4j
@Api(tags = "es控制器")
@RestController
@RequestMapping("/es")
public class EsController {
    @Resource
    private EsFileService fileService;

    /**
     * 导入所有文档
     */
    @GetMapping("/importAllDoc")
    public String importAllDoc() {
        fileService.importAllDoc();
        return "导入完成";
    }

    /**
     * 删除所有文档
     */
    @GetMapping("/deleteAllDoc")
    public String deleteAllDoc() {
        fileService.deleteAllDoc();
        return "删除完成";
    }

    /**
     * 根据关键字查询文档
     *
     * @param map 参数map
     */
    @PostMapping("/queryDoc")
    public Map<String, Object> queryDoc(@RequestBody Map<String, Object> map) {
        return fileService.queryDoc(map);
    }

    @PostMapping("/addEsFile")
    public Integer queryDoc(@RequestBody EsFile esFile) {
        return fileService.addEsFile(esFile);
    }
}
